package com.sto.common.result;

import java.io.Serializable;

/**
 * @author ChenPeng
 * @since 2022-07-15 12:17
 */
public class ResultView<T> implements Serializable {
    private static final long serialVersionUID = -1L;
    public static final String ERROR_CODE = "9999";
    public static final String SUCCESS_CODE = "200";
    public static final String SUCCESS_MSG = "success";
    public static final String ERROR_MSG = "error";
    private String code;
    private String msg;
    private T data;
    private Boolean success;

    private ResultView() {
    }

    public static ResultView error(String code, String message) {
        ResultView resultView = new ResultView();
        resultView.setCode(code);
        resultView.setMsg(message);
        resultView.setSuccess(false);
        return resultView;
    }

    public static ResultView errorMsg(String message) {
        return error("9999", message);
    }

    public static ResultView error() {
        return error("9999", "error");
    }

    public static ResultView successMsg(String message) {
        ResultView resultView = new ResultView();
        resultView.setCode("200");
        resultView.setMsg(message);
        resultView.setSuccess(true);
        return resultView;
    }

    public static ResultView success() {
        return successMsg("success");
    }

    public static <V> ResultView<V> success(String message, V data) {
        ResultView resultView = new ResultView();
        resultView.setCode("200");
        resultView.setMsg(message);
        resultView.setData(data);
        resultView.setSuccess(true);
        return resultView;
    }

    public static <V> ResultView<V> success(V data) {
        return success("success", data);
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return this.success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String toString() {
        return "ResultView{code='" + this.code + '\'' + ", msg='" + this.msg + '\'' + ", data=" + this.data + ", success=" + this.success + '}';
    }
}
